import axios from '../../src/index';

axios({
  method: 'post',
  url: '/extend/post',
  data: {
    msg: 'HEllO '
  }
}).then(res => {
  console.log('>>>>', res);
}).catch(e => {
  console.error('eeeee', e)
})

axios.request({
  method: 'post',
  url: '/extend/post',
  data: {
    msg: 'Hello Tom!!!'
  },
}).then(res => {
  console.log('44444', res);
}).catch(e => {
  console.error(e)
});

axios.get('/extend/get');
axios.options('/extend/options');
axios.delete('/extend/delete');
axios.head('/extend/head');

axios.post('/extend/post', { msg: 'post' });
axios.put('/extend/put', { msg: 'put' });
axios.patch('/extend/patch', { msg: 'patch' });


// 验证 axios 的函数重载, 传递一个或者两个参数
// 一个参数
axios({
  url: '/extend/post',
  method: 'post',
  data: {
    msg: 'haha'
  }
})
// 两个参数
axios('/extend/post', {
  method: 'post',
  data: {
    msg: 'hehe'
  }
})

// 测试泛型接口
interface ResponseData<T = any> {
  code: number
  result: T
  message: string
}
interface IUser {
  name: string
  age: number
  sex: string
}

const getUser = <T>() => {
  return axios<ResponseData<T>>('/extend/user')
    .then(res => res.data)
    .catch(err => console.error(err))
}

async function test() {
  const user = await getUser<IUser>();
  if (user) {
    console.log('>>>result', user.result)
  }
}

test();